package com.homedo.odin.solution.enumcode;

import java.util.Arrays;
import lombok.Getter;

/**
 * @author ：ZhangLei
 * @Date ：2018/4/24
 */
@Getter
public enum PublicAuditStatusEnum {
    ALREADY_DEL(0, "已删除"),
    AUDITING(10, "待审核"),
    AUDIT_SUCCESS(20, "审核通过"),
    AUDIT_FAIL(21, "审核不通过"),
    SHELVES(30, "上架中"),
    UNSHELVES(31, "下架中");

    private Integer dbValue;
    private String displayValue;

    PublicAuditStatusEnum(Integer dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(PublicAuditStatusEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(PublicAuditStatusEnum.values())
                .anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(PublicAuditStatusEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
